<html lang="en">
<head>
    <title>商品分类管理</title>
    <#include "../common/header.ftl">
    
    <script>
        //页面加载完成
        $(function () {

           //模态窗 新增/编辑js
            $(".inputBtn").click(function () {

                //清空模态窗内容
                $("#editForm input").val("");
                $("#typeUrl").attr("src", "");
                //判断是否要进行回显,json为空就不进去
                var json = $(this).data('json');//得到一个json对象
                if (json){
                    //获取a标签里面的data-json数据

                    $("#editForm input[name='id']").val(json.id);
                    $("#editForm input[name='typeName']").val(json.typeName);
                    $("#typeUrl").attr("src", json.typeUrl);//取出json 里面的参数,赋值到input里面
                }

                //点击按钮,打开模态窗
                $("#myModal").modal('show');
            })


            //点击保存,提交表单
            $(".saveBtn").click(function () {
                $("#editForm").submit();
            })


            //给删除按钮绑定事件
            $(".deleteBtn").click(function () {
                //点击删除,弹出是否删除的提示框
                var ret = confirm("你确认要删除吗?");
                if (ret){ //判断ret 为true执行删除
                    //发起删除请求
                    $.get($(this).data("url"),function (data) {
                        if (data.success){
                            //删除成功,刷新页面
                            window.location.reload();
                        }
                    })
                }
            })
        })
    </script>
</head>
<body>
<#--左侧菜单回显变量设置 使用freemarker-->

<#assign currentMenu="productType">

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-3">
            <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">商品分类管理</h1>
                </div>
            </div>

            <form class="form-inline" id="searchForm" action="/productType/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">

                <div class="form-group">
                    <label>关键字:</label>
                    <input type="text" class="form-control" name="keyword" value="${(qo.keyword)!}"
                           placeholder="请输入商品分类名称">
                </div>
                <button id="btn_query" class="btn btn-info">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>
                <a role="button" class="btn btn-success inputBtn">
                    <span class="glyphicon glyphicon-plus"></span> 新增
                </a>

            </form>
            <table class="table table-striped table-hover" >
                <thead>
                    <tr>
                        <th>编号</th>
                        <th>分类图片</th>
                        <th>分类名称</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <#--freemaker 遍历-->
                <#list pageInfo.list as entity>
                   <tr>
                       <td>${entity.id}</td>
                       <td><img src="${(entity.typeUrl)!}" width="50px"/></td>
                       <td>${entity.typeName}</td>
                       <td>
                           <a role="button" class="btn btn-danger btn-xs inputBtn" data-json='${entity.json}'>
                               <span class="glyphicon glyphicon-pencil"></span> 修改
                           </a>
                           <a href="javascript:;" class="btn btn-danger btn-xs deleteBtn" data-url="/productType/delete.do?id=${entity.id}">
                               <span class="glyphicon glyphicon-trash"></span> 删除
                           </a>
                       </td>
                   </tr>
                </#list>
            </table>
             <#include "../common/page.ftl">
        </div>
    </div>
</div>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">新增/编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/productType/saveOrUpdate.do" method="post" id="editForm" enctype="multipart/form-data" >
                    <input type="hidden" name="id"/>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">分类图片：</label>
                        <div class="col-lg-6">
                            <img id="typeUrl" style="width: 80%"/>
                            <input type="file" class="form-control" name="img"/>
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="name" class="col-sm-3 control-label">分类名称：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="typeName" name="typeName">
                        </div>
                    </div>

                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">退出</button>
                <button type="button" class="btn btn-primary saveBtn">保存</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>